import axios from 'axios'
import { getToken } from './getToken'
import { message } from 'antd'
const request = axios.create({
    baseURL: 'http://127.0.0.1:8082',
    timeout: 5000,
})

// 请求拦截器
request.interceptors.request.use(
    (config:any) => { 
        const token = getToken()
        config.headers["Authorization"] = `Bearer ${token}`
        return config
})
// 响应拦截器
request.interceptors.response.use(
    (response:any) => {
        if (response.data.code !== 200) {
            message.error(`请求失败: ${response.data.message}`)
        }
        return response.data
    }
)


export default request
